﻿#include "setup4wind.h"
#include "ui_setup4wind.h"
#include <mainwindow.h>
extern intListener doorStatus;
setup4wind::setup4wind(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::setup4wind)
{
    ui->setupUi(this);
    connect(&doorStatus, &intListener::valueChanged,this,&setup4wind::doorStatusChanged,Qt::QueuedConnection);
#ifdef Q_OS_ANDROID
    int fontId = QFontDatabase::addApplicationFont(":/FontStyle/AlibabaPuHuiTi-3-55-Regular.ttf");
    if (fontId != -1) {
        QStringList fontFamilies = QFontDatabase::applicationFontFamilies(fontId);
        if (!fontFamilies.isEmpty()) {
            QString familyName = fontFamilies.first();
            QFont font(familyName, 18); // 创建一个QFont对象，设置字体名称和默认大小

            // 使用setFont方法设置字体，传入QFont对象
            ui->label->setFont(font);
            ui->BeginBtn->setFont(font);


            // 如果需要为其他按钮设置不同的大小，可以创建新的QFont对象
            QFont smallerFont(familyName, 16);
            ui->returnBtn_2->setFont(familyName);
            ui->pushButton_10->setFont(familyName);
        }
    }
#endif
}
void setup4wind::doorStatusChanged(){
    if(doorStatus.get()==0)
    {
        ui->pushButton_10->setText("        打开仓门");
    }
    else
    {
        ui->pushButton_10->setText("        关闭仓门");
    }
}

setup4wind::~setup4wind()
{
    delete ui;
}

void setup4wind::showEvent(QShowEvent *event)
{
    tcpClient = TcpClient::getInstance();
    if(doorStatus.get()==0)
    {
        ui->pushButton_10->setText("        打开仓门");
    }
    else
    {
        ui->pushButton_10->setText("        关闭仓门");
    }
    event->accept();
}

void setup4wind::on_returnBtn_2_clicked()
{
    this->close();
    emit changeTotalWindow();
}


void setup4wind::on_BeginBtn_clicked()
{
    this->close();
    emit changeTotalWindow();
}


void setup4wind::on_pushButton_10_clicked()
{
    if(doorStatus.get()==0)
    {
        doorStatus.set(1);
        ui->pushButton_10->setText("        关闭仓门");
    }
    else
    {
        doorStatus.set(0);
        ui->pushButton_10->setText("        打开仓门");
    }
}

